<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="85px" class="queryForms">
			<el-form-item label="工艺流名称" prop="technologyName">
				<el-input maxlength="20" show-word-limit  v-model="queryParams.technologyName" placeholder="请输入工艺流名称" clearable @keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
				<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>

		<el-row :gutter="10" class="mb8">
			<el-col :span="1.5">
				<el-button size="mini" type="info" @click="handleBacks">返回</el-button>
			</el-col>
			<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
		</el-row>

		<div :class="sidebar.opened && eleTabTop <= 85 ? 'eleTab' : !sidebar.opened && eleTabTop <= 85 ? 'eleTabs' : ''" class="informationTab" ref="eleTab">
			<el-table ref="table" @row-click="row_click" v-loading="loading" :data="tableData" border height="100%">
				<el-table-column label="序号" align="center" width="55" type="index" />
				<el-table-column label="工艺流名称" prop="technologyName" :show-overflow-tooltip="true" align="center" />
				<el-table-column label="工艺流编码" prop="technologyCode" :show-overflow-tooltip="true" align="center" />
				<el-table-column label="工艺流字典" prop="technologyDictCode" :show-overflow-tooltip="true" align="center" />
				<el-table-column label="计划完成时间" prop="plannedTime" :show-overflow-tooltip="true" align="center" />
				<el-table-column label="备注" prop="remark" width="200" :show-overflow-tooltip="true" align="center" />
				<el-table-column label="创建时间" prop="createTime" width="160" :show-overflow-tooltip="true" align="center" />
				<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="160">
					<template slot-scope="scope">
						<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['erp:productStep:update']">修改</el-button>
					</template>
				</el-table-column>
			</el-table>
		</div>

		<pagination menuNames="Pagination34" v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

		<!-- 添加或修改对话框 -->
		<el-dialog title="修改产品步骤时间" :visible.sync="open" width="500px" append-to-body v-dialogDrag>
			<el-form ref="form" :model="form" :rules="rules" label-width="110px">
				<el-form-item label="工艺流名称" prop="technologyName">
					<el-input v-model="form.technologyName" placeholder="请输入工艺流名称" maxlength="20" show-word-limit  readonly />
				</el-form-item>
				<el-form-item label="计划完成时间" prop="plannedTime">
					<el-input v-model.number="form.plannedTime" oninput="value=value.replace(/[^\d]/g,'')" placeholder="请输入计划完成时间" maxlength="5"  />
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitForm">确 定</el-button>
				<el-button @click="cancel">取 消</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
import { getListData, updateRow } from "@/api/product/productStep"
import { mapGetters } from "vuex"
import { getcolumn } from "@/api/selectList"
export default {
	computed: {
		...mapGetters(["sidebar"])
	},
	name:'ProductStep',
	data() {
		return {
      productId:'',
			eleTabTop: 0, //表格容器距浏览器顶部距离
			// 遮罩层
			loading: true,
			// 显示搜索条件
			showSearch: true,
			// 总条数
			total: 0,
			// 产品零组件表格数据
			tableData: [],
			// 是否显示弹出层
			open: false,
			// 查询参数
			queryParams: {
				pageNum: 1,
				pageSize: 10,
				technologyName: null,
				productId: null
			},
			// 表单参数
			form: {},
			// 表单校验
			rules: {
				technologyName: [{ required: true, message: "", trigger: "blur" }],
				plannedTime: [{ required: true, message: "请输入计划完成时间", trigger: "blur" }]
			}
		}
	},
	created() {
    	this.productId = this.$route.query.id
		this.getSize()
	},
	mounted() {
		// 滚动条的获取
		this.handleScrollx()
		window.addEventListener("scroll", this.handleScrollx, true)
	},
	activated() {
		this.productId = this.$route.query.id
		this.getSize()
		this.handleScrollx()
	},
	destroyed() {
		window.removeEventListener("scroll", this.handleScrollx, true)
	},
	methods: {
    getSize() {
			getcolumn({ pageName: "Pagination34" }).then(response => {
				this.queryParams.pageSize = response.data.length ? (response.data[0].limit ? response.data[0].limit : 10) : 10
				this.getList()
			})
		},
    // 单击表格行
		row_click(row, column, event) {
      if(column && column.label=='操作'){
        return;
      }else{
        this.$refs.table.toggleRowSelection(row)
      }
		},
		handleBacks() {
			// 关闭当前tab页签，打开新页签
			const obj = { path: "/product/product_menu" }
			this.$tab.closeOpenPage(obj)
		},
		//获取表格容器距页面头部的距离
		handleScrollx() {
			this.eleTabTop = this.$refs.eleTab.getBoundingClientRect().top
		},
		/** 查询产品零组件列表 */
		getList() {
			this.loading = true
			this.queryParams.productId = this.productId
			getListData(this.queryParams).then(response => {
				this.tableData = response.rows
				this.total = response.total
				this.loading = false
			})
		},
		// 取消按钮
		cancel() {
			this.open = false
			this.reset()
		},
		// 表单重置
		reset() {
			this.form = {
        plannedTime:undefined,
        technologyName:undefined,
      }
			this.resetForm("form")
		},
		/** 搜索按钮操作 */
		handleQuery() {
			this.queryParams.pageNum = 1
			this.getList()
		},
		/** 重置按钮操作 */
		resetQuery() {
			this.resetForm("queryForm")
			this.handleQuery()
		},
		/** 修改按钮操作 */
		handleUpdate(row) {
			this.reset()
			this.form = row
			this.open = true
		},
		/** 提交按钮 */
		submitForm() {
			this.$refs["form"].validate(valid => {
				if (valid) {
					updateRow(this.form).then(() => {
						this.$modal.msgSuccess("修改成功")
						this.open = false
						this.getList()
					})
				}
			})
		}
	}
}
</script>
